<template>
	<view class="container">
		<navbar title="申请提现"></navbar>
		<view class="wrap">
			<view class="base-wrap withdraw-wrap">
				<view class="title line-v-center">
					<text>提现金额</text>
					<view class="all" @tap='drawAll'>全部</view>
				</view>
				<view class="money-con line-center">
					<text>￥</text>
					<input placeholder="输入提现金额" v-model="cashMoney" type="text" @input="getVal" placeholder-style="font-size:28rpx"/>
				</view>
				<view class="true line-v-center">
					<view class="true-rate">提现手续费：{{rateMoney}}元</view>
					<view class="true-cash">实际到账：{{paymentMoney}}元</view>
				</view>
			</view>
			<view class="base-wrap user-cash-wrap">
				<view class="cash-item">
					<label>真实信息</label>
					<view class="cash-item-con">{{form.realname}}</view>
				</view>
				<view class="cash-item">
					<label>身份信息</label>
					<view class="cash-item-con">{{form.idNum}}</view>
				</view>
				<view class="cash-item">
					<label>开户行</label>
					<view class="cash-item-con">{{form.bankName}}</view>
				</view>
				<view class="cash-item">
					<label>银行卡号</label>
					<view class="cash-item-con">{{form.cardNum}}</view>
				</view>
			</view>
			<view class="tip-wrap">
				<!-- <view class="tip">{{cashDesc}}</view> -->
				<view class="tip">
					<rich-text :nodes="cashDesc"></rich-text>
				</view>
			</view>
			<button class="btn line-center" :disabled="isDisabled" @tap='drawMoney'>确认</button>
		</view>
	</view>
</template>

<script>
	const app = getApp()
	export default {
		data() {
			return {
				form:{},
				cashMoney:'',
				commssion:0,
				rateMoney:0,
				paymentMoney:0,
				cashDesc:'',
				isDisabled:true,
			};
		},
		onLoad(option) {
			this.commssion = option.money;
			this.getCashDetail()
		},
		methods:{
			getCashDetail(){
				app.globalRequest({
					api:app.getApi().promotion.cashInfo,
				}).then(res=>{
					if (res.code == 0) {
						this.form = res.data.userAccount;
						this.cashDesc = res.data.cashSetting.cash_desc
					} 
				})
			},
			getVal(e){
				console.log('e',e)
				this.cashMoney = this.$trim(e.detail.value);
				if(this.cashMoney){
					this.isDisabled = false
				}else{
					this.isDisabled = true
				}
				this.getDrawRate(this.cashMoney ? this.cashMoney :0)
			},
			drawAll(){
				this.cashMoney = this.commssion;
				if(this.cashMoney){
					this.isDisabled = false
				}else{
					this.isDisabled = true
				}
				this.getDrawRate(this.cashMoney ? this.cashMoney :0)
			},
			getDrawRate(price = 0){
				app.globalRequest({
					api:app.getApi().promotion.cash,
					data:{
						price,
					}
				}).then(res=>{
					if (res.code == 0) {
						this.rateMoney = res.data.serviceMoney;
						this.paymentMoney = res.data.payment_money;
					} else{
						uni.showToast({
							title: res.msg,
							icon: 'none',
							mask: true
						})
						this.rateMoney = 0;
						this.paymentMoney = 0;
					}
				})
			},
			drawMoney(){
				let that = this;
				if(!that.cashMoney){
					uni.showToast({
						title: '请输入提现金额',
						icon: 'none',
						mask: true
					})
					return;
				}
				app.globalRequest({
					api:app.getApi().promotion.cash,
					method:'POST',
					data:{
						price:that.cashMoney
					}
				}).then(res=>{
					if (res.code == 0) {
						uni.showToast({
							title: res.msg,
							icon: 'none',
							mask: true
						})
						setTimeout(()=>{
							uni.navigateBack({
								delta:1
							})
						},300)
					} else{
						uni.showToast({
							title: res.msg,
							icon: 'none',
							mask: true
						})
					}
				})
				
			}
			
		}
	}
</script>

<style lang="scss" scoped>
	.base-wrap{
		margin:24rpx 24rpx 0;
		background: #fff;
		border-radius: 16rpx;
	}
	.withdraw-wrap{
		padding:46rpx 24px 32rpx;
		.title{
			justify-content: space-between;
		}
		.money-con{
			padding:56rpx 0;
			border-bottom: 2rpx solid #F2F3F9;
			text{
				font-size: 36rpx;
			}
			input{
				height: 36rpx;
				font-size: 28rpx;
			}
		}
		.true{
			justify-content: space-between;
			padding-top:30rpx;
			.true-rate{
				font-size: 24rpx;
				color: #666666;
			}
			.true-cash{
				font-size: 24rpx;
				color: #EC1818;
			}
		}
	}
	.user-cash-wrap{
		padding:0 24rpx;
		.cash-item{
			width: 100%;
			height: 88rpx;
			display: flex;
			align-items: center;
			border-bottom: 2rpx solid #F2F3F9;
			&:last-of-type{
				border-bottom: 0;
			}
			label{
				width: 112rpx;
				font-weight: bold;
				margin-right: 38rpx;
			}
			.cash-item-con{
				flex:1;
			}
		}
	}
	.tip-wrap{
		margin:24rpx 24rpx 0;
		font-size: 24rpx;
		line-height: 34rpx;
	}
	.btn{
		width: 640rpx;
		height: 94rpx;
		background: #52B148;
		border-radius: 48rpx;
		color:#fff;
		font-size: 32rpx;
		margin-top:56rpx;
		
	}
	.btn[disabled]:not([type]),
	.btn[disabled][type=default] {
		color: #fff !important;
		background: #E2E2E2 !important;
	}
</style>
